const fs = require('fs')
const baseFile = {
    read (path, uid='') {
        return new Promise(resolve => {
            fs.readFile(path,function(err,data) {
                if (err) return console.log('文件读取失败' + err);
                    if (data.toString().includes(uid) && uid) return;
                    resolve(data.toString())
            });
        })
    },
    write (path, content, uid) {
        return new Promise(resolve => {
            let writeContent = '';
                if (!content) writeContent = `'${uid}'`;
            else
                writeContent = `${content},'${uid}'`;
            console.log('在线玩家列表：', writeContent)

            fs.writeFile(path, writeContent,function(err){
                if (err) return console.log('文件写入失败' + err)
                resolve()
            })
        })
    }
}
module.exports = baseFile